package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAdmin;
import com.qf.service.AdminService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理员管理
 * @author lixu
 */
@RestController
@RequestMapping("/admin/admin")
@CrossOrigin
public class AdminController {

    @Autowired
    private AdminService adminService;

    /**
     * ##### . 管理员列表
     *
     * - 接口地址 : http://localhost:8083/admin/admin/list?page=1&limit=20&sort=add_time&order=desc
     * - GET请求
     * - 下行数据 :
     *
     *
     */
    //权限
    @RequiresPermissionsDesc(menu = {"系统管理","管理员"},button = "查询")
    @RequiresPermissions(value = {"admin:admin:list"})
    @GetMapping("/list")
    public Object adminList(Integer page,Integer limit,String sort,String order,String username){
        //1:查询管理员的分页数据
        IPage<DtsAdmin> iPage = adminService.adminPage(page,limit,sort,order,username);
        Map map = new HashMap<>();
        map.put("total",iPage.getTotal());
        map.put("items",iPage.getRecords());
        return ResponseUtil.ok(map);

    }
    /**
     *#####  管理员修改
     *
     * - 接口地址 : http://localhost:8083/admin/admin/update
     * - 上行数据
     * {
     * 	"avatar": "https://juhuixing-public.oss-cn-shenzhen.aliyuncs.com/pi47cqg6ubw47vefxic6.jpg",
     * 	"id": 12,
     * 	"mail": "123456@qq.com",
     * 	"password": "123456",
     * 	"roleIds": [
     * 		25
     * 	],
     * 	"tel": "13452046647",
     * 	"username": "itsource"
     * }
     *
     */
    //权限
    @RequiresPermissionsDesc(menu = {"系统管理","管理员"},button = "编辑")
    @RequiresPermissions(value = {"admin:admin:update"})
    @PostMapping("/update")
    public Object update(@RequestBody DtsAdmin dtsAdmin){
        //修改
        adminService.update(dtsAdmin);
        return ResponseUtil.ok();
    }

    /**
     * 添加
     */




}
